<template>
  <el-row :gutter="20">
    <el-col :span="4">
      <div class="grid-content bg-purple">&emsp;&emsp;&emsp;</div>
    </el-col>
    <el-col :span="16">
      <div class="grid-content bg-purple">

        <div class="ww">
          <!--查询表单-->
          <el-form :inline="true" class="demo-form-inline">
            <el-form-item>
              <el-input v-model="condition.dictName" placeholder="类型名称" />
            </el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="query()">查询</el-button>
            <el-button type="default" @click="resetData()">清空</el-button>
            <el-button @click="Jump" type="success">添加</el-button>
            <!-- <router-link > -->
            <!-- <el-button @click="Jump" type="success">成功按钮</el-button> -->
          </el-form>
        </div>



        <el-table
          ref="singleTable"
          :data="tableData"
          highlight-current-row
          @current-change="handleCurrentChange"
          style="width: 100%"
        >
          <el-table-column type="index"></el-table-column>
          <el-table-column label="Code" prop="dictCode"></el-table-column>
          <el-table-column label="Name" prop="dictName"></el-table-column>
          <el-table-column label="Description" prop="description"></el-table-column>
          <el-table-column label="CreateTime" prop="createTime"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">Edit</el-button>
              <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.$index, scope.row)"
              >Delete</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination
          :current-page="cs.page.current"
          :page-size="cs.page.size"
          :total="cs.page.total"
          style="padding: 30px 0; text-align: center;"
          layout="total, prev, pager, next, jumper"
          @current-change="queryPage"
        />
      </div>
    </el-col>
    <el-col :span="4">
      <div class="grid-content bg-purple">&emsp;&emsp;&emsp;</div>
    </el-col>
  </el-row>
</template>


<script>
import dictType from "@/api/dictType";
export default {
  data() {
    return {
      tableData: [],
      search: "",
      condition:{},
      page: {
          current: 1,
          size: 10,
          total: 0
        } ,
      cs: {
      }
    };
  },
   created() {
    this.queryPage();
  },
  methods: {
    //删除数据
    remove(id) {
      this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return dictType.del(id).then(() => {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.queryPage();
          });
        })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!"
          });
          this.query();
        })
        .catch(response => {
          // 失败
          if (response === "cancel") {
            this.$message({
              type: "info",
              message: "已取消删除"
            });
          }
        });
    },
    handleEdit(index, row ) {
      this.$router.push({
        path: "/stuteacher/addDictType/" +row.dictTypeId
      });
      
    },
    handleDelete(index, row) {
      
      this.remove(row.dictTypeId)
    },
    queryPage() {
        this.cs.page=this.page
      dictType.queryPage(this.cs).then(response => {
        this.tableData = response.data.list.records;
        this.cs.page.current = response.data.list.current;
        this.cs.page.list = response.data.list.list;
        this.cs.page.total = response.data.list.total;
      });
    },
    query(){
        debugger
          this.cs.dictType=this.condition
          this.queryPage();
      },
      resetData(){
         this.cs={}
         this.cs.page=this.page
         this.condition={} 
         this.queryPage();
      },
      handleCurrentChange(){

      },
      Jump() {
      this.$router.push({
        path: "/stuteacher/addDictType/" 
      });
      }
      
  }
};
</script>

<style>
.ww{
    margin-top:30px ;
}
</style>